<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="p" value="${param}"></c:set>
<div class="easyui-layout" style="width:100%;height:98%;" fit="true">
    <div data-options="region:'center',title:'',split:true" style="height:98%;">
	<form id="productDetailForm" method="post" >
	<table class="detailTable">
		<tr>
			<th>选择商品：</th>
			<td>
				<input type="hidden" name="productCode" id="d_productCode" value="">
				<input type="text" name="chsName" id="d_chsName" data-options="required:true" missingmessage="请选择商品" readonly="readonly">
				<a href="#" onclick="chooseProduct()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">选择</a>
			</td>
			</tr>
	   <tr>
			<th>专题链接：</th>
			<td>
				<input type="text" name="promoUrl" style="width: 500px;"  class="easyui-validatebox" data-options="required:true"  >
			</td>
	   </tr>
	   <tr>
			<th>开始日期：</th>
			<td>
				<input type="text" name="beginTime"   class="easyui-datebox" data-options="required:true"  >
			</td>
	   </tr>
	   <tr>
			<th>结束日期：</th>
			<td>
				<input type="text" name="endTime"   class="easyui-datebox" data-options="required:true"  >
			</td>
	   </tr>
       <tr>
			<th>排序值：</th>
			<td>
				<input type="text" class="easyui-numberspinner" value="0" name="sortOrder"   style="width: 70px;">
			</td>
		</tr>
        <tr>
			<th>促销简介：</th>
			<td>
				<textarea rows="2" cols="100" name="promoDesc" data-options="required:true" ></textarea>	
			</td>
			</tr>
         
        <tr>
			<td align="center" colspan="2">
				<input type="button" onclick="submitForm()" class="button" value="提交" >
				<input type="button" onclick="pms.resetForm('productDetailForm')" class="button" value="重置" >
			</td>
		</tr>
	</table>
</form>	
</div>
</div>	 
<script type="text/javascript">
$(function(){
	var productCode = "<c:out value="${p.productCode}" />";
	if(productCode!=""){
		var param = {"productCode":"<c:out value="${p.productCode}" />"}
		$.pmsAjax({
			url : '<c:url value="/product/searchAllProductDetail.do"/>',
			data : param,
			success : function(data) {
				if(data.code==200){
					$('#productDetailForm').form('load', data.data.productDetail);
	
					if(data.data.productDetail.isControlSale==1){
						chooseControlSale('show');
					}else{
						chooseControlSale('hide');
					}
				}
			}
		});
	}

	 
	
});


function submitForm(){
	
	$('#productDetailForm').form('submit', {
	    url:'<c:url value="/product/insertProductPromo.do"/>',
	    onSubmit: function(param){
	    	if(!$("#productDetailForm").form('validate')){
	    		return false;
	    	}
	    },
	    success:function(data){
		    var ret = eval("("+data+")")
	     	if(ret.code=="200"){
	     		 alertShow("保存成功");
	     		promoProductsTable.refresh();
	     		 $("#w_product_promo").dialog('close');
		    }else{
		    	alertError(ret.result);
			}
	    }
	});
} 

//选择商品
function chooseProduct(){
	$.pmsDialog({
		title:'选择商品',
		id:"w_choose_p",
		method:'post',
		href:'<c:url value="/views/jsp/product/productForChooselist.jsp"/>',
		width:800,
		params:{
			"singleSelect":true
		}
	});
}
//接收商品
function receiveProduct(param){
	//console.log(param['productList[0].chsName']);
	 $("#d_productCode").val(param['productList[0].productCode']);
	 $("#d_chsName").val(param['productList[0].chsName']);
	 $("#w_choose_p").dialog('close');
}

</script>
